package SearchTree;

import BufferReader.BufferReader;

public class SearchNodeReader extends BufferReader{

	byte key = 0;
	byte info = 0;
	
	public SearchNodeReader(byte[] bs) {
		super(bs);
	}

	public char ReadNode(){
		key = ReadByte();
		info = ReadByte();
		return (char)key;
	}
	
	public boolean GotoBrother() {
		if(SearchNode.Node(info, SearchNode.HasBrother)) {
			PassNodeEnd();
			return true;
		} else {
			return false;
		}
	}
	
	public boolean GotoChild() {
		if(SearchNode.Node(info, SearchNode.HasChild)) {
			PassChildOff();
			Skip(ReadInt());
			return true;
		}
		return false;
	}
	
	public boolean IsFinishNode() {
		return SearchNode.Node(info, SearchNode.IsFinish);
	}
	
	private void PassNodeEnd() {
		if(SearchNode.Node(info, SearchNode.IsFinish)) {
			Skip(SearchNode.IntByteCount * 2);
		}
		if(SearchNode.Node(info, SearchNode.HasChild)) {
			Skip(SearchNode.IntByteCount);
		}
	}
	
	private void PassChildOff() {
		if(SearchNode.Node(info, SearchNode.IsFinish)) {
			Skip(SearchNode.IntByteCount * 2);
		}
	}
}
